package com.lans.table;

/**
 * @author: lans
 * @date: 2025/3/6
 * @name: 刘宇
 */
public class StudentLinkedList {

    //头指针
    private Student head;

    public void add(Student student){
        if(head == null){
            head = student;
            return;
        }
        Student temp = head;
        while(true){
            if(temp.next==null){
                break;
            }
            temp  = temp.next;
        }
        temp.next = student;
    }

    public void list() {
        if(head == null){
            System.out.println("List is empty");
            System.out.println();
            return;
        }
        Student temp = head;
        while(true){
            System.out.println("学生编号名称"+temp.id+temp.name);
            if(temp.next==null){
                break;
            }
            temp = temp.next;
        }
        System.out.println();
    }
    public Student findByStudentID(int id){
        if(head==null){
            System.out.println("链表为空");
            return null;
        }
        Student temp = head;
        while(true){
            if(temp.id==id){
                break;
            }
            if(temp.next==null) {
                temp = null;
                break;
            }
            temp =temp.next;
        }
        return temp;
    }

}